package com.cwvs.cat.adapter;

import java.util.List;
import net.tsz.afinal.FinalBitmap;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.cwvs.cat.R;
import com.cwvs.cat.bean.MyFriend;
import com.cwvs.cat.net.Port;

public class InviteFriendListAdapter extends BaseAdapter{
	
    private Activity activity;
	private List<MyFriend> list_contact;
	private LayoutInflater inflater;
	private FinalBitmap fb;
	public InviteFriendListAdapter() {
		// TODO Auto-generated constructor stub
	}

	public InviteFriendListAdapter(Activity ac, List<MyFriend> list) {
		// TODO Auto-generated constructor stub
		this.activity = ac;
		this.inflater = LayoutInflater.from(ac);
		this.list_contact = list;
		fb= FinalBitmap.create(ac);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_contact.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list_contact.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.item_list_invite_friend,
					parent,false);
			viewholder = new ViewHolder();
			viewholder.txt_invite_friend_name = (TextView) convertView
					.findViewById(R.id.txt_invite_friend_name);
			viewholder.img_invite = (ImageView)convertView.findViewById(R.id.img_invite);
			viewholder.image = (ImageView)convertView.findViewById(R.id.image);
			viewholder.sign = (TextView)convertView.findViewById(R.id.sign);
			convertView.setTag(viewholder);
		} else {
			viewholder = (ViewHolder) convertView.getTag();
		}
		viewholder.txt_invite_friend_name.setText(list_contact.get(position).nickname);
		viewholder.sign.setText(list_contact.get(position).sign);
		if (!list_contact.get(position).avatar.equals("")&&!list_contact.get(position).avatar.equals("null")) {
			fb.display(viewholder.image, Port.getImg+list_contact.get(position).avatar);
		}
		return convertView;
	}

	class ViewHolder {
		TextView txt_invite_friend_name, txt_my_message_time,sign;
		ImageView img_invite,image;
	}
}
